from sqlalchemy.orm import class_mapper
import datetime

def serialize(model):
    columns=[c.key for c in class_mapper(model.__class__).columns]
    res=[]
    for c in columns:
        if isinstance(getattr(model,c),datetime.datetime):
            res.append((c,getattr(model,c).strftime('%Y-%m-%d %H:%M:%S')))
        else:
            res.append((c,getattr(model,c)))
    return dict(res)